#ifndef __TIMER0_H__
#define __TIMER0_H__
#include "timer_config.h"

#if USE_TIMER0

/*********************配置*************************/
//  通道选择
#define TIMER0_CH0_ENABLE 1
#define TIMER0_CH1_ENABLE 0
#define TIMER0_CH2_ENABLE 0
#define TIMER0_CH3_ENABLE 0
#define TIMER0_BRKIN_ENABLE 1 // 刹车功能


//-- -- -- -- -- -- -- -- -刹车功能配置- -- -- -- -- -- -- -- -- -- --
#if TIMER0_BRKIN_ENABLE     // 可选  PA6  PB12  PE15
#define TIMER0_BRKIN_PORT_RCU RCU_GPIOA   
#define TIMER0_BRKIN_PORT     GPIOA
#define TIMER0_BRKIN_PIN      GPIO_PIN_6
#define TIMER0_BRKIN_DEADTIME 10     // 死区时间 0——255
#endif

//-- -- -- -- -- -- -- -- -通道 CH0 配置-- -- -- -- -- -- -- -- -- -- --
#if TIMER0_CH0_ENABLE
// 通道极性: 一路还是成对的pwm
#define TIMER0_CH0_P_ENABLE 1
#define TIMER0_CH0_N_ENABLE 1
#define TIMER0_ETI_ENALBE   1
// 引脚选择
#if TIMER0_CH0_P_ENABLE // 可选  PA8 PE9
#define TIMER0_CH0_P_PORT_RCU RCU_GPIOA
#define TIMER0_CH0_P_PORT GPIOA
#define TIMER0_CH0_P_PIN GPIO_PIN_8
#define TIMER0_CH0_P_POLARITY TIMER_OC_POLARITY_HIGH // TIMER_OC_POLARITY_HIGH  输出高电平 | TIMER_OC_POLARITY_LOW   输出低电平
#endif

#if TIMER0_CH0_N_ENABLE // 可选  PA7  PB13  PE8
#define TIMER0_CH0_N_PORT_RCU RCU_GPIOA
#define TIMER0_CH0_N_PORT GPIOA
#define TIMER0_CH0_N_PIN GPIO_PIN_7
#define TIMER0_CH0_N_POLARITY TIMER_OCN_POLARITY_HIGH  // TIMER_OCN_POLARITY_HIGH  输出高电平 | TIMER_OCN_POLARITY_LOW
#endif

#endif


//-- -- -- -- -- -- -- -- -通道 CH1 配置-- -- -- -- -- -- -- -- -- -- --
#if TIMER0_CH1_ENABLEd
#define TIMER0_CH1_P_ENABLE 1
#define TIMER0_CH1_N_ENABLE 1

#if TIMER0_CH1_P_ENABLE // 可选  PA9 PE11
#define TIMER0_CH1_P_PORT_RCU RCU_GPIOA
#define TIMER0_CH1_P_PORT GPIOA
#define TIMER0_CH1_P_PIN GPIO_PIN_9
#define TIMER0_CH1_P_POLARITY TIMER_OC_POLARITY_HIGH
#endif

#if TIMER0_CH1_N_ENABLE // 可选  PB0 PB14 PE1 PE10
#define TIMER0_CH1_N_PORT_RCU RCU_GPIOB
#define TIMER0_CH1_N_PORT GPIOB
#define TIMER0_CH1_N_PIN GPIO_PIN_0
#define TIMER0_CH1_N_POLARITY TIMER_OCN_POLARITY_LOW
#endif
#endif

//-- -- -- -- -- -- -- -- -通道 CH2 配置-- -- -- -- -- -- -- -- -- -- --
#if TIMER0_CH2_ENABLE
#define TIMER0_CH2_P_ENABLE 1
#define TIMER0_CH2_N_ENABLE 1
#if TIMER0_CH2_P_ENABLE // 可选  PA10 PE13
#define TIMER0_CH2_P_PORT_RCU RCU_GPIOA
#define TIMER0_CH2_P_PORT GPIOA
#define TIMER0_CH2_P_PIN GPIO_PIN_10
#define TIMER0_CH2_P_POLARITY TIMER_OC_POLARITY_HIGH
#endif

#if TIMER0_CH2_N_ENABLE // 可选  PB1 PB15 PE12
#define TIMER0_CH2_N_PORT_RCU RCU_GPIOB
#define TIMER0_CH2_N_PORT GPIOB
#define TIMER0_CH2_N_PIN GPIO_PIN_1
#define TIMER0_CH2_N_POLARITY TIMER_OCN_POLARITY_LOW
#endif
#endif
//-- -- -- -- -- -- -- -- -通道 CH3 配置-- -- -- -- -- -- -- -- -- -- --
#if TIMER0_CH3_ENABLE
#define TIMER0_CH3_P_ENABLE 1
#if TIMER0_CH3_P_ENABLE // 可选  PA11  PE14
#define TIMER0_CH3_P_PORT_RCU RCU_GPIOA
#define TIMER0_CH3_P_PORT GPIOA
#define TIMER0_CH3_P_PIN GPIO_PIN_11
#define TIMER0_CH3_P_POLARITY TIMER_OC_POLARITY_HIGH
#endif
#endif


//-- -- -- -- -- -- -- -- -对外输出函数 -- -- -- -- -- -- -- -- -- -- --
void timer0_init();

#if TIMER0_CH0_ENABLE
void timer0_ch0_update(float duty);
#endif
#if TIMER0_CH1_ENABLE
void timer0_ch1_update(float duty);
#endif
#if TIMER0_CH2_ENABLE
void timer0_ch2_update(float duty);
#endif
#if TIMER0_CH3_ENABLE
void timer0_ch3_update(float duty);
#endif

#endif
#endif